//
//  WCDrawBorderView.m
//  WC
//
//  Created by 杨鑫 on 15/5/14.
//  Copyright (c) 2015年 智康. All rights reserved.
//

#import "WCDrawBorderView.h"


@implementation WCDrawBorderView

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    UIBezierPath *path = [[UIBezierPath alloc] init];
    
    if (_leftBorder) {
        CGPoint start = CGPointMake(0, 0);
        CGPoint end = CGPointMake(0, rect.size.height);
        [path moveToPoint:CGPointPathChange(start, kLineVertical, 1)];
        [path addLineToPoint:CGPointPathChange(end, kLineVertical, 1)];
    }
    
    if (_rightBorder) {
        CGPoint start = CGPointMake(rect.size.width, 0);
        CGPoint end = CGPointMake(rect.size.width, rect.size.height);
        [path moveToPoint:CGPointPathChange(start, kLineVertical, -1)];
        [path addLineToPoint:CGPointPathChange(end, kLineVertical, -1)];
    }
    
    if (_topBorder) {
        CGPoint start = CGPointMake(0, 0);
        CGPoint end = CGPointMake(rect.size.width, 0);
        [path moveToPoint:CGPointPathChange(start, kLineHorizontal, 1)];
        [path addLineToPoint:CGPointPathChange(end, kLineHorizontal, 1)];
    }
    
    if (_bottomBorder) {
        CGPoint start = CGPointMake(0, rect.size.height);
        CGPoint end = CGPointMake(rect.size.width, rect.size.height);
        [path moveToPoint:CGPointPathChange(start, kLineHorizontal, -1)];
        [path addLineToPoint:CGPointPathChange(end, kLineHorizontal, -1)];
    }
    
    path.lineWidth = kOnePX;
    [_borderColor setStroke];

    [path stroke];
}

@end
